package com.onefish.toolkit.controller;

import com.onefish.toolkit.service.ThreadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api/thread")
public class ThreadController {
    @Autowired
    private ThreadService threadService;
    @GetMapping("/hello")
    public String hello(Model model){
        model.addAttribute("index","index");
        return "thread/index";
    }
    @GetMapping("/cpuLoadTopNThreads")
    public String thread(HttpServletRequest request, HttpServletResponse response, Model model){
        String processId = request.getParameter("processId");
        Integer n = Integer.valueOf(request.getParameter("n"));
//        System.out.println("------------"+threadService.cpuLoadTopNThreads(processId,n));
        String s = "[\n" +
                "\t{\n" +
                "\t\t\"c\":\"123\"\n" +
                "\t},\n" +
                "\t{\n" +
                "\t\t\"c\":\"123\"\n" +
                "\t},\n" +
                "\t{\n" +
                "\t\t\"c\":\"123\"\n" +
                "\t}\n" +
                "]";
        System.out.println("s-------------------------");
        System.out.println(s);
        return s;
//        return threadService.cpuLoadTopNThreads(processId,n);
    }
}
